/*
注:以下的整型数最低位为bit0.
(1)随机给定一个16位无符号整型数a的值.然后,设置a的bit3为1,保持其他位不变.
(2)随机给定一个16位无符号整型数b的值.然后,设置b的bit3和bit7为0,保持其他位不变.
(3)随机给定一个16位无符号整型数var1的值.然后,设置var1的bit4-bit13为1,保持其他位不变.
(4)随机给定一个32位无符号整型数var2的值.然后取出var2的bit3-bit8.
(5)随机给定一个32位无符号整型数var3的值.快速将其除以8并打印出结果.
(6)随机给定一个32位无符号整型数var4的值.快速将其乘以2并打印出结果.
*/
#include <stdio.h>
#include "../MyFunc/MyFunc.c" //包含自定义的函数
int main(void)
{
	//    (1)
	unsigned short int a = 0;
//	a = rand() * 65535;
	a = myFuncGenU16RandNum();
	printf("(1)\n随机a的二进制数为:\n");
	myFuncUint16ToBin(a);
	a |= 1 << 3;
	printf("\n置位后,a的二进制数为:\n");
	myFuncUint16ToBin(a);


	//    (2)
	unsigned short int b = 0;
//	b = rand() * 65535;
	b = myFuncGenU16RandNum();
	printf("\n(2)\n随机b的二进制数为:\n");
	myFuncUint16ToBin(b);
	b = b & ~(1 << 3); // set bit3 to 0
	b = b & ~(1 << 7); // set bit7 to 0
	printf("\n置位后,b的二进制数为:\n");
//    myFuncToBin(b);
	myFuncUint16ToBin(b);

	//    (3)
	unsigned short int var1 = 0;
//	var1 = rand() * 65535;
	var1 = myFuncGenU16RandNum();
	printf("\n(3)\n随机var1的二进制数为:\n");
	myFuncUint16ToBin(var1);
	var1 = var1 | (0x1FF << 4); // set bit4-bit13 to 1
	printf("\n置位后,var1的二进制数为:\n");
	myFuncUint16ToBin(var1);

	//    (4)
	unsigned int var2 = 0;
//	var2 = rand() * 65535 * 65535;
	var2 = myFuncGenU32RandNum();
	printf("\n(4)\n随机var2的二进制数为:\n");
	myFuncUint32ToBin(var2);
	var2 = var2 & (0x3F << 3); //取出var2的bit3-bit8
	var2 = var2 >> 3;
	printf("\n取出的数的二进制数为:\n");
	myFuncUint32ToBin(var2);

	//    (5)
	unsigned int var3 = 0;
//	var3 = rand() * 65535 * 65535;
	var3 = myFuncGenU32RandNum();
	printf("\n(5)\n随机var3的二进制数为:\n");
	myFuncUint32ToBin(var3);
	var3 = var3 >> 3; //快速除以8
	printf("\n快速除以8后所得二进制数为:\n");
	myFuncUint32ToBin(var3);


	//    (6)
	unsigned int var4 = 0;
//	var4 = rand() * 65535;
	var4 = myFuncGenU32RandNum();
	printf("\n(6)\n随机var4的二进制数为:\n");
	myFuncUint32ToBin(var4);
	var4 = var4 << 1; //快速乘以2
	printf("\n快速乘以后2所得二进制数为:\n");
	myFuncUint32ToBin(var4);


}
